import 'package:boss/models/store_menu.dart';
import 'package:boss/provider/commodity_provider.dart';
import 'package:boss/ui/page/commodity/classificationManagement/page/classificationDetail/classification_detail_page.dart';
import 'package:boss/ui/widget/loader/empty_widget.dart';
import 'package:boss/ui/widget/loader/loader.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'classification_management_item.dart';

class ClassificationManagementList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Loader(
      loadTask: Provider.of<CommodityProvider>(context, listen: false).initData,
      builder: (context) {
        return Consumer<CommodityProvider>(
          builder: (context, commodityProvider, child) {
            if (commodityProvider.storeMenus.length == 0) return EmptyWidget();

            return ListView.builder(
              padding: EdgeInsets.symmetric(
                horizontal: 30.w,
              ),
              itemBuilder: (context, index) {
                var current = commodityProvider.storeMenus[index];

                return ClassificationManagementItem(
                  key: ValueKey('classification_id_${current.menuId}'),
                  data: current,
                  onTap: () {
                    Navigator.pushNamed(
                      context,
                      ClassificationDetailPage.pageName,
                      arguments: {
                        'storeMenu': StoreMenu.fromJson(current.toJson()),
                      },
                    );
                  },
                );
              },
              itemCount: commodityProvider.storeMenus.length,
            );
          },
        );
      },
    );
  }
}
